var text = "------WebKitFormBoundaryDZFWVoVFzPCwJg0J\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\n3\r\n------WebKitFormBoundaryDZFWVoVFzPCwJg0J\r\nContent-Disposition: form-data; name=\"file\"; filename=\"1.txt\"\r\nContent-Type: text/plain\r\n\r\n解压密码：itjc8.com_jvnj8AKFmlF3E93E\n\n\n\r\n------WebKitFormBoundaryDZFWVoVFzPCwJg0J--\r\n"
let LF = 10, //换行  line feed
  CR = 13, //回车 carriage return
  SPACE = 32, //空格
  COLON = 58; //冒号

var boundary = '----WebKitFormBoundaryDZFWVoVFzPCwJg0J'

var buf = Buffer.from(text)

// console.log(buf.slice(0, 10).toString(),1212)
// console.log(buf.toString())
var state = 'start'
var index = 0;
console.log(buf.length)
var map = {};
for (i = 0; i < buf.length; i++) {
  var char = buf[i];
  // var map = {}
  switch (state) {
    case 'start':
      state = 'handleboundary'
      break;
    case 'handleboundary':
      // console.log(char ,CR)
      if (char == CR) {
        var bound = buf.slice(index, i)
        if ('--' + bound + '--' === boundary) {
          state = 'end'
          return;
        }
        break;
      } else if (char == LF) {
        //回车
        index = i;
        
        state = 'Disposition'; // 分析请求头（header）
      }
      break;
    case 'Disposition':
      if (char == CR) {
        let mydata = buf.slice(index + 1, i).toString()
        //  console.log(index, i,'??',,'???')

        mydata.split('; ').forEach(row => {
          var [key, value] = row.split('=')
          map[key] = value;
        });

        break;
      } else if (char == LF) {
        //回车
        if (buf[i + 1] == CR && buf[i + 2] == LF) {
          i = i + 2;
          state = 'DispositionValue';
        }
        index = i;
        //  state = 'Disposition'; // 分析请求头（header）
      }

      break;
    case 'DispositionValue':
      // console.log(char, CR)
      // console.log(char, LF)
      if (char == CR) {
        let DispositionValue = buf.slice(index + 1, i);
        map['value'] = DispositionValue.toString();
        console.log(map)
        map = {};
        state = 'handleboundary'
        break;
      }

      break;
    case 'end':
      break;

    default:
      break;
  }

}